/**
 * 字典处理工具
 */

/**
 * 将字典对象转换为数组
 * @param {Object} obj - 需要转换的字典对象
 * @param {Array} fieldList - 需要提取的字段列表（可选）
 * @param {*} emptyValue - 当字段不存在时的默认值
 * @returns {Array} - 转换后的数组
 */
export function convertDictToArray(obj, fieldList, emptyValue) {
  if (!fieldList?.length) {
    return Object.values(obj); // 如果未提供字段列表，则返回所有对象值的数组
  }
  return Object.values(obj).map((item) => {
    return fieldList.reduce((cur, field) => {
      cur[field] = item[field] || emptyValue; // 仅保留指定字段，并填充默认值
      return cur;
    }, {});
  });
}

/**
 * 按指定字段转换字典对象
 * @param {Object} obj - 需要转换的字典对象
 * @param {string} field - 作为新字典键的字段名
 * @param {*} emptyValue - 当字段不存在时的默认值
 * @returns {Object} - 转换后的字典对象，以指定字段值为键
 */
export function convertDictByField(obj, field, emptyValue) {
  return Object.values(obj).reduce((cur, item) => {
    cur[item[field]] = item || emptyValue; // 以指定字段值为键，存入新对象
    return cur;
  }, {});
}
export const DELIVERY_TYPE = {
  SELF: {
    name: "门店自提",
    value: 1,
  },
  EXPRESS: {
    name: "快递配送",
    value: 2,
  },
};
export const EXPRESS_TYPE = {
  FREE: {
    name: "免邮",
    value: 1,
    price: 0,
  },
  ZT: {
    name: "中通",
    value: 2,
    price: 0,
  },
  SF: {
    name: "顺丰",
    value: 3,
    price: 0,
  },
  YT: {
    name: "圆通",
    value: 4,
    price: 0,
  },
  DF: {
    name: "到付",
    value: 5,
    price: 0,
  },
};
export const BUSINESS_TYPE = {
  ALL: {
    name: "全部",
    value: 0,
  },
  PROCUREMENT: {
    name: "采购",
    value: 1,
    color: "#E8FFEA",
    img: "/static/images/inventory/buy.png",
  },
  SALES: {
    name: "销售",
    value: 2,
    color: "#E8F5FF",
    img: "/static/images/inventory/sale.png",
  },
  AFTER: {
    name: "售后",
    value: 3,
  },
};
